package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.Collect;
import com.example.flshtarvel.entity.RouteCollectMap;
import com.example.flshtarvel.mapper.CollectMapper;
import com.example.flshtarvel.mapper.RouteCollectMapMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Service
public class CollectService {
//    @Autowired(required = false)
//    RouteCollectMapMapper routeCollectMapMapper;
    @Autowired(required = false)
    CollectMapper collectMapper;

    //路线点赞
    public int collect(Collect collect){
        List<Collect> collectList = collectMapper.selectCollectByMessageIdAndUserId(collect.getMessageId(),collect.getUserId());
        if(collectList==null|| collectList.size()==0 ){
            int result = collectMapper.collect(collect);
            return result;
        }else{
            return 0;
        }
    }

    //取消点赞
    public int deleteCollect(String messageId,String userId){
        int result = collectMapper.deleteCollect(messageId,userId);
        return result;
    }

    //查询点赞    根据路线id 用户id
    public int selectCollectByMessageIdAndUserId(String messageId, String userId){
        List<Collect> collectList = collectMapper.selectCollectByMessageIdAndUserId(messageId,userId);
        int result;
        if(collectList.size()==0||collectList==null){
            result=0;
        }else{
            result=1;
        }
        return result;
    }

    //查询点赞数    根据路线id
    public int selectCollectByMessageId(String messageId){
        int result = collectMapper.selectCollectByMessageId(messageId);
        return result;
    }

    //查询收藏 根据用户id
    public List<Collect> selectCollectByUserId(String userId){
        return collectMapper.selectCollectByUserId(userId);
    }
}
